package gamejam.game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferedImage;

import redsoxfan.gamejam.base.DesktopWrapper;
import redsoxfan.gamejam.base.Game;
import redsoxfan.gamejam.base.GameResource;

public class MainGame extends Game implements KeyListener{
	private Map map;
	private Player player;
	
	public String authors() {
		return "Brian Ashworth and Spencer Rak";
	}

	public String beforeApplet() {
		return infoBlock("http://3hrgamejam.com", "3hr Game Jam (Practice)", "April 29, 2014", "Control More Than One (LD Theme)", "Get to the end. We went with too complicated of an idea so the theme does not really show.", "Use A and D to move left and right. Use W to jump.");
	}
	
	public void draw(Graphics g) {
		map.draw(g);
		g.setColor(Color.GREEN);
		g.fillRect((int) (player.getX() - map.getViewport().getMinX()), (int)(player.getY() - map.getViewport().getMinY()),
				Map.TILE_SIZE, Map.TILE_SIZE);
	}

	public Image icon() {
		return new BufferedImage(32, 32, BufferedImage.TYPE_INT_RGB);
	}

	public void init() {
		addKeyListener(this);
		try {
			map = new Map(GameResource.loadResource("/gamejam/game/map.txt"), width(), height());
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(0);
		}
		player = new Player(map);
	}

	public String shortTitle() {
		return "TBD";
	}

	public void tick() {
		player.tick();
		map.center(player.getCenterX(), player.getCenterY());
	}

	public String title() {
		return "TBD";
	}

	public static void main(String[] args) {
		new DesktopWrapper(new MainGame());
	}

	public void keyPressed(KeyEvent e) {
		player.passPressedKeys(e);
	}
	public void keyReleased(KeyEvent e) {
		player.passReleasedKeys(e);
	}
	public void keyTyped(KeyEvent e) {}

}
